package com.itmk.business.transport.controller;

import com.itmk.business.transport.entity.Transport;
import com.itmk.business.transport.service.TransportService;
import com.itmk.result.DataResult;
import com.itmk.vo.req.TransportReqVO;
import com.itmk.vo.resp.PageRespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/api/transport")
public class TransportController {

    @Autowired
    private TransportService service;

    @RequestMapping("/getlist")
    @ResponseBody
    public DataResult getTransportList(@RequestBody TransportReqVO vo){
        PageRespVO<Transport> pageRespVO=service.getTransportsList(vo);
        return DataResult.success(pageRespVO);
    }

    @PostMapping("/savetransport")
    @ResponseBody
    public DataResult saveTransport(@RequestBody Transport transport){
        Boolean b=service.save(transport);
        if(b){
            return DataResult.success();
        }else{
            return DataResult.getResult(300100,"物流信息保存出错");

        }
    }

    @GetMapping("/getbyid")
    @ResponseBody
    public DataResult getTransportById(@RequestParam("id") String id){
        Transport t=service.getById(id);
        if(t!=null){
            return DataResult.success(t);
        }else{
            return DataResult.getResult(300100,"物流信息查询出错");

        }
    }

    @GetMapping("/deletebyid")
    @ResponseBody
    public DataResult deleteTransportById(@RequestParam("id") String id){
        Boolean t=service.removeById(id);
        if(t){
            return DataResult.success();
        }else{
            return DataResult.getResult(300100,"物流信息删除出错");

        }
    }

    @PostMapping("/updatetransport")
    @ResponseBody
    public DataResult updateTransport(@RequestBody Transport transport){
        Boolean t=service.updateById(transport);
        if(t){
            return DataResult.success();
        }else{
            return DataResult.getResult(300100,"物流信息更新出错");

        }
    }
}
